package com.sophialex.health.record.lktable.cellstyle;

import java.util.Date;
import java.util.Iterator;
import java.util.Set;

import org.apache.commons.httpclient.util.DateUtil;

import com.sophia.dict.vo.DictCode;
import com.sophialex.health.common.platform.SuperContext;
import com.sophialex.health.record.common.utils.CommonUtils;
import com.sophialex.health.system.lktable.LKCellStyleProvider;

public class FamilyMemberCellStyleProvider extends LKCellStyleProvider {
	public String getTipInfo(Object element,String field,Object byValue){
		if(byValue!=null){
			if(byValue instanceof Date){
				Date date = new Date(Date.parse(byValue.toString()));
				return DateUtil.formatDate(date,"yyyy-MM-dd");
			}
			if ("adminUserId".equals(field)) { 
				 if(byValue!=null && !"".equals(byValue)){
					 try {
						 
						 return CommonUtils.getUserNameById(Long.valueOf(byValue.toString()));
					}
					catch(Exception e) {
						e.printStackTrace();
					}
				 }
			}
			if ("perRelaMaster".equals(field)) { 
				 if(byValue!=null){
					 try {
						 Set<DictCode> set = SuperContext.dictCache.getCodesByName("RELATION");
						 Iterator it = set.iterator();
						 while(it.hasNext()){
							 DictCode dict = (DictCode) it.next();
							 if(dict.getCodeNum().equals(byValue.toString())){
								 return dict.getCodeValue();
							 }
						 }
					}
					catch(Exception e) {
						e.printStackTrace();
					}
				 }
			}
			if ("sex".equals(field)) { 
				 if(byValue!=null){
					 try {
						 Set<DictCode> set = SuperContext.dictCache.getCodesByName("SEX");
						 Iterator it = set.iterator();
						 while(it.hasNext()){
							 DictCode dict = (DictCode) it.next();
							 if(dict.getCodeNum().equals(byValue.toString())){
								 return dict.getCodeValue();
							 }
						 }
					}
					catch(Exception e) {
						e.printStackTrace();
					}
				 }
			}
			return byValue.toString();
		}else{
			return null;
		}
	}
}
